import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAppStore = defineStore('app', () => {
  // 状态
  const loading = ref<boolean>(false)
  const collapsed = ref<boolean>(false)
  const theme = ref<'light' | 'dark'>('light')
  const language = ref<'zh-CN' | 'en-US'>('zh-CN')

  // 方法
  const setLoading = (status: boolean) => {
    loading.value = status
  }

  const toggleSidebar = () => {
    collapsed.value = !collapsed.value
  }

  const setSidebarCollapsed = (status: boolean) => {
    collapsed.value = status
  }

  const setTheme = (newTheme: 'light' | 'dark') => {
    theme.value = newTheme
    // 这里可以添加主题切换逻辑
    document.documentElement.setAttribute('data-theme', newTheme)
  }

  const setLanguage = (lang: 'zh-CN' | 'en-US') => {
    language.value = lang
  }

  return {
    // 状态
    loading,
    collapsed,
    theme,
    language,
    // 方法
    setLoading,
    toggleSidebar,
    setSidebarCollapsed,
    setTheme,
    setLanguage
  }
}, {
  persist: {
    key: 'app-store',
    storage: localStorage,
    paths: ['collapsed', 'theme', 'language']
  }
}) 